'use strict';
module.exports = app => {
  class AtMeController extends app.Controller {
    async index() {
      const { id: userId } = this.ctx.session.userInfo;
      // 获取 atMe 未读的数量
      const atCount = await this.ctx.service.atRelation.getAtCount(userId)
      // 获取 atMe 的微博列表
      const result = await this.service.atRelation.getAtMeBlogList({ userId, pageIndex: 0, pageSize: 10 })
      await this.ctx.render('atMe.html', {
        blogList: result.blogList,
        count: result.count,
        pageIndex: 1,
        pageSize: 10,
        atCount,
      });

      // 将 atMe 变成已读
      await this.service.atRelation.update({ newIsRead: true }, { userId, isRead: false })
    }
  }
  return AtMeController;
};
